package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.DietAry;
import com.itheima.service.DietAryService;
import com.itheima.utils.POIUtils;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping(path = "/dietary")
public class DietAryController {

    @Reference
    private DietAryService dietAryService;

    //分页查询
    @PostMapping(path = "/findDietAryByCondition")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        //分页查询
        try {
            PageResult pageResult = dietAryService.pageQuery(queryPageBean);
            return new Result(true, MessageConstant.QUERY_DIETARY_SUCCESS, pageResult);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_DIETARY_FAIL);
        }
    }

    /*@GetMapping(path = "/findAll")
    public Result findAll() {
        try {
            List<DietAry> dietAryList = dietAryService.findAll();
            return new Result(true, MessageConstant.QUERY_DIETAR_SUCCESS, dietAryList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_DIETAR_FAIL);
        }
    }*/

    @GetMapping("/findAll")
    public Result findAll() {
        List<DietAry> dietAryList = dietAryService.findAll();

        return new Result(true,MessageConstant.QUERY_DIETAR_SUCCESS,dietAryList);
    }



}

